package com.macro.mall.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;

/**
 * 数据看板核心指标DTO
 * Created by AI on 2025/09/15.
 */
@Data
@ApiModel("数据看板核心指标")
public class DashboardStatsDTO {
    
    @ApiModelProperty("商品交易总额GMV(元)")
    private BigDecimal gmv;
    
    @ApiModelProperty("GMV环比增长率(%)")
    private BigDecimal gmvGrowthRate;
    
    @ApiModelProperty("订单总数")
    private Long totalOrders;
    
    @ApiModelProperty("订单总数环比增长率(%)")
    private BigDecimal ordersGrowthRate;
    
    @ApiModelProperty("支付用户数")
    private Long payingUsers;
    
    @ApiModelProperty("支付用户数环比增长率(%)")
    private BigDecimal usersGrowthRate;
    
    /**
     * 格式化GMV显示
     */
    public String getFormattedGmv() {
        if (gmv == null) return "¥0";
        
        // 如果金额大于10万，显示为万元
        if (gmv.compareTo(new BigDecimal("100000")) >= 0) {
            BigDecimal wan = gmv.divide(new BigDecimal("10000"), 1, BigDecimal.ROUND_HALF_UP);
            return "¥" + wan + "万";
        }
        
        return "¥" + gmv.setScale(2, BigDecimal.ROUND_HALF_UP);
    }
    
    /**
     * 格式化订单数显示
     */
    public String getFormattedOrders() {
        if (totalOrders == null) return "0";
        
        // 如果订单数大于10000，显示为万
        if (totalOrders >= 10000) {
            BigDecimal wan = new BigDecimal(totalOrders).divide(new BigDecimal("10000"), 1, BigDecimal.ROUND_HALF_UP);
            return wan + "万";
        }
        
        return totalOrders.toString();
    }
    
    /**
     * 格式化用户数显示
     */
    public String getFormattedUsers() {
        if (payingUsers == null) return "0";
        
        // 如果用户数大于10000，显示为万
        if (payingUsers >= 10000) {
            BigDecimal wan = new BigDecimal(payingUsers).divide(new BigDecimal("10000"), 1, BigDecimal.ROUND_HALF_UP);
            return wan + "万";
        }
        
        return payingUsers.toString();
    }
    
    /**
     * 获取GMV增长率显示样式
     */
    public String getGmvGrowthStyle() {
        if (gmvGrowthRate == null || gmvGrowthRate.compareTo(BigDecimal.ZERO) == 0) {
            return "neutral";
        }
        return gmvGrowthRate.compareTo(BigDecimal.ZERO) > 0 ? "positive" : "negative";
    }
    
    /**
     * 获取订单增长率显示样式
     */
    public String getOrdersGrowthStyle() {
        if (ordersGrowthRate == null || ordersGrowthRate.compareTo(BigDecimal.ZERO) == 0) {
            return "neutral";
        }
        return ordersGrowthRate.compareTo(BigDecimal.ZERO) > 0 ? "positive" : "negative";
    }
    
    /**
     * 获取用户增长率显示样式
     */
    public String getUsersGrowthStyle() {
        if (usersGrowthRate == null || usersGrowthRate.compareTo(BigDecimal.ZERO) == 0) {
            return "neutral";
        }
        return usersGrowthRate.compareTo(BigDecimal.ZERO) > 0 ? "positive" : "negative";
    }
}
